import 'package:flutter/material.dart';
import 'package:fluttermodule/router/RouterHelper.dart';
import 'dart:ui';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyApp();
  }
}

//页面的起点入口
class _MyApp extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    //获取原生跳转的url地址
    var routerUrl = _getRouterUrl(window.defaultRouteName);
    print('flutter-->$routerUrl');
    _getRouterParam(window.defaultRouteName);
    return RouterHelper.routerWidget(routerUrl.isNotEmpty ? routerUrl : '/');
  }
}

//获取真实的路由地址
String _getRouterUrl(String winUrl) {
  if (winUrl.indexOf("?") == -1) {
    return winUrl;
  } else {
    return winUrl.substring(0, winUrl.indexOf("?"));
  }
}

//获取路由参数
_getRouterParam(String winUrl) {
  if (winUrl.indexOf("?") != -1) {
    RouterHelper.setRouterParam(winUrl.substring(winUrl.indexOf("?") + 1));
  }
}
